package app.util;

import java.awt.Point;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;

/**
 * @author Evstigneev Kirill (kester)
 */
public class Utils {

	public static JButton createButton( final String iconPath, final String tooltip, final ActionListener l ) {
		final JButton b = createButton(iconPath, tooltip);
		b.addActionListener(l);
		return b;
	}

	public static JButton createButton( final String iconPath, final String tooltip) {
		final JButton b = new JButton(new ImageIcon(iconPath));
		b.setToolTipText(tooltip);
		return b;
	}

	public static void centerFrame( final JFrame parent, final JFrame toCenter ) {
		final Point parentLocation = parent.getLocation();
		int x = ((Double)parentLocation.getX()).intValue() + toCenter.getWidth()/2;
		int y = ((Double)parentLocation.getY()).intValue() + toCenter.getHeight()/2;
		toCenter.setLocation( x, y );
	}

}
